<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta name="description" content="智能交易系统 - 股票分析与自动交易平台">
  <title>智能交易系统</title>
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  <style>
    :root {
      --primary-color: #4CAF50;
      --secondary-color: #2196F3;
      --danger-color: #F44336;
      --dark-bg: #333;
      --light-bg: #f5f5f5;
      --border-color: #ccc;
      --text-light: white;
    }
    
    * {
      box-sizing: border-box;
    }
    
    body { 
      font-family: 'Arial', 'Microsoft YaHei', sans-serif; 
      margin: 0; 
      padding: 0; 
      line-height: 1.6;
      color: #333;
    }
    
    .tabs { 
      display: flex; 
      background-color: var(--dark-bg); 
      position: sticky;
      top: 0;
      z-index: 100;
    }
    
    .tab { 
      padding: 14px 20px; 
      cursor: pointer; 
      color: var(--text-light); 
      transition: background-color 0.3s;
    }
    
    .tab:hover {
      background-color: #444;
    }
    
    .tab.active { 
      background-color: #555; 
      font-weight: bold;
    }
    
    .content { 
      padding: 20px; 
      display: none; 
      animation: fadeIn 0.3s ease;
    }
    
    @keyframes fadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }
    
    .content.active { 
      display: block; 
    }
    
    .stock { 
      display: flex; 
      align-items: center; 
      justify-content: space-between; 
      margin-bottom: 15px; 
      padding: 12px;
      border-radius: 4px;
      transition: background-color 0.2s;
    }
    
    .stock:hover {
      background-color: rgba(0, 0, 0, 0.03);
    }
    
    .stock-info { 
      flex: 1; 
      font-size: 16px;
    }
    
    .chart-container { 
      width: 200px; 
      height: 60px;
      position: relative;
    }
    
    .change { 
      width: 80px; 
      text-align: right;
      font-weight: bold;
    }
    
    .positive { 
      color: var(--primary-color); 
    }
    
    .negative { 
      color: var(--danger-color); 
    }
    
    .btn {
      padding: 8px 16px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 14px;
      transition: opacity 0.3s, transform 0.2s;
    }
    
    .btn:hover {
      opacity: 0.9;
      transform: translateY(-1px);
    }
    
    .btn:active {
      transform: translateY(0);
    }
    
    .btn-primary {
      background-color: var(--primary-color);
      color: white;
    }
    
    .btn-secondary {
      background-color: var(--secondary-color);
      color: white;
    }
    
    .btn-small {
      padding: 3px 8px;
      font-size: 12px;
    }
    
    /* 模态框样式 */
    .modal {
      display: none;
      position: fixed;
      z-index: 1000;
      left: 0; 
      top: 0;
      width: 100%; 
      height: 100%;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      background-color: rgba(0, 0, 0, 0.5);
      animation: fadeIn 0.3s ease;
    }
    
    .modal-content {
      background-color: #fff;
      margin: 20px auto;
      padding: 24px;
      border-radius: 8px;
      width: 90%;
      max-width: 600px;
      max-height: 90vh;
      overflow-y: auto;
      position: relative;
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    }
    
    .close {
      position: absolute;
      right: 20px;
      top: 15px;
      font-size: 24px;
      cursor: pointer;
      color: #777;
      transition: color 0.2s;
    }
    
    .close:hover {
      color: #333;
    }

    .stock-search-result {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 0;
      border-bottom: 1px solid var(--border-color);
      transition: background-color 0.2s;
    }
    
    .stock-search-result:hover {
      background-color: rgba(0, 0, 0, 0.03);
    }
    
    .form-group {
      margin-bottom: 20px;
    }
    
    .form-group label {
      display: block;
      margin-bottom: 8px;
      font-weight: bold;
    }
    
    .form-control {
      width: 100%;
      padding: 10px;
      border: 1px solid var(--border-color);
      border-radius: 4px;
      font-size: 14px;
    }
    
    .form-control:focus {
      outline: none;
      border-color: var(--primary-color);
      box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
    }
    
    .checkbox-group {
      margin-bottom: 15px;
    }
    
    .checkbox-label {
      display: inline-flex;
      align-items: center;
      margin-right: 20px;
      cursor: pointer;
    }
    
    .checkbox-label input {
      margin-right: 6px;
    }
    
    .search-input {
      position: relative;
    }
    
    .search-results {
      max-height: 300px;
      overflow-y: auto;
      border: 1px solid var(--border-color);
      border-radius: 4px;
      margin-top: 5px;
      display: none;
    }
    
    .loading {
      padding: 10px;
      text-align: center;
      color: #777;
    }
    
    /* 响应式设计 */
    @media (max-width: 768px) {
      .stock {
        flex-direction: column;
        align-items: flex-start;
      }
      
      .chart-container {
        width: 100%;
        margin: 10px 0;
      }
      
      .change {
        text-align: left;
      }
      
      .modal-content {
        width: 95%;
        margin: 10px auto;
        padding: 15px;
      }
    }
    
    /* 移动端特定样式 */
    @media (max-width: 480px) {
      .tab {
        padding: 12px 10px;
        font-size: 14px;
      }
      
      .modal-content {
        margin: 10px auto;
        padding: 15px;
        max-height: 85vh;
      }
      
      .form-control, .btn {
        font-size: 16px;
      }
      
      /* 防止移动端输入框缩放 */
      input, select, textarea {
        font-size: 16px !important;
      }
      
      /* 移动端策略表单滚动修复 */
      #new-strategy {
        max-height: calc(100vh - 80px);
        overflow-y: auto;
      }
      
      .checkbox-label {
        display: flex;
        margin-right: 0;
        margin-bottom: 10px;
      }
      
      .content {
        padding: 15px;
      }
    }
  </style>
</head>
<body>
  <div class="tabs">
    <div class="tab active" onclick="showTab(0)">自选股票</div>
    <div class="tab" onclick="showTab(1)">策略交易</div>
    <div class="tab" onclick="showTab(2)">智能选股</div>
  </div>

  <!-- 自选股票标签页 -->
  <div class="content active" id="tab0">
    <div class="search-input">
      <input type="text" class="form-control" placeholder="搜索股票代码/名称" id="stockSearch" />
    </div>
    
    <div id="watchlist">
      <div class="stock" data-stock="600519">
        <div class="stock-info">贵州茅台 (600519)</div>
        <div class="chart-container"><canvas id="chart1"></canvas></div>
        <div class="change positive">+1.23%</div>
      </div>
      <div class="stock" data-stock="300750">
        <div class="stock-info">宁德时代 (300750)</div>
        <div class="chart-container"><canvas id="chart2"></canvas></div>
        <div class="change negative">-0.85%</div>
      </div>
    </div>
  </div>

  <!-- 策略交易标签页 -->
  <div class="content" id="tab1">
    <button class="btn btn-primary" onclick="toggleStrategyForm()">添加新策略</button>
    
    <div class="strategy-list" id="strategyList">
      <div class="strategy" style="margin-top: 20px; padding: 15px; background: var(--light-bg); border-radius: 4px;">
        <strong>策略一：</strong> TWAP + MACD<br />
        <small>股票：贵州茅台、宁德时代</small>
        <div style="margin-top: 10px;">
          <span class="badge" style="background: #e3f2fd; color: #1976d2; padding: 2px 8px; border-radius: 12px; font-size: 12px;">运行中</span>
          <span style="float: right;">
            <button class="btn btn-secondary btn-small">详情</button>
            <button class="btn btn-small" style="margin-left: 5px;">停止</button>
          </span>
        </div>
      </div>
    </div>
  </div>

  <!-- 策略模态框 -->
  <div id="strategyModal" class="modal">
    <div class="modal-content">
      <span class="close" onclick="toggleStrategyForm()">&times;</span>
      <div id="new-strategy">
        <h3 style="margin-top: 0;">新建策略</h3>
        
        <div class="form-group">
          <label>已选择股票:</label>
          <div id="selectedStocks">
            <div class="stock" data-stock="600519">
              <div class="stock-info">贵州茅台 (600519)</div>
              <div class="chart-container"><canvas id="chart3"></canvas></div>
              <button class="btn btn-small" onclick="removeStock(this)">移除</button>
            </div>
          </div>
        </div>
        
        <div class="form-group">
          <label>添加股票:</label>
          <input type="text" class="form-control" placeholder="搜索股票" id="stockSearchInput" oninput="debounceSearch()" />
          <div id="searchResults" class="search-results">
            <div class="loading">输入股票代码或名称搜索...</div>
          </div>
        </div>
        
        <div class="form-group">
          <label>委托资金量:</label>
          <input type="number" class="form-control" placeholder="输入金额(元)" min="1000" step="1000" />
        </div>
        
        <div class="form-group">
          <label>交易算法：</label>
          <select class="form-control">
            <option value="TWAP">TWAP (时间加权平均价格)</option>
            <option value="VWAP">VWAP (成交量加权平均价格)</option>
            <option value="Iceberg">冰山订单</option>
            <option value="Sniper">狙击手订单</option>
          </select>
        </div>
        
        <div class="form-group">
          <label>交易信号：</label>
          <div class="checkbox-group">
            <label class="checkbox-label"><input type="checkbox" checked /> MACD</label>
            <label class="checkbox-label"><input type="checkbox" /> RSI</label>
            <label class="checkbox-label"><input type="checkbox" /> KDJ</label>
            <label class="checkbox-label"><input type="checkbox" /> 均线交叉</label>
          </div>
          <div style="display: flex; align-items: center; gap: 15px;">
            <div>
              <label style="display: block; font-size: 13px; color: #666; margin-bottom: 3px;">止盈</label>
              <input type="number" placeholder="n%" style="width:80px; padding: 6px; border: 1px solid var(--border-color); border-radius: 4px;" min="0" step="0.1" />
            </div>
            <div>
              <label style="display: block; font-size: 13px; color: #666; margin-bottom: 3px;">止损</label>
              <input type="number" placeholder="n%" style="width:80px; padding: 6px; border: 1px solid var(--border-color); border-radius: 4px;" min="0" step="0.1" />
            </div>
          </div>
        </div>
        
        <div class="form-group" style="margin-top: 30px;">
          <button class="btn btn-primary" style="width: 100%; padding: 12px;">保存策略</button>
        </div>
      </div>
    </div>
  </div>

  <!-- 智能选股标签页 -->
  <div class="content" id="tab2">
    <h3 style="margin-top: 0;">智能选股</h3>
    
    <form id="screeningForm" style="margin-bottom: 20px;">
      <div class="form-group">
        <label class="checkbox-label">
          <input type="checkbox" name="roe" /> ROE 长期稳定高于
          <input type="number" name="roeValue" placeholder="15" style="width: 50px; padding: 5px; margin-left: 5px;" min="0" step="1" />%
        </label>
      </div>
      
      <div class="form-group">
        <label class="checkbox-label">
          <input type="checkbox" name="grossMargin" /> 毛利率 >
          <input type="number" name="grossMarginValue" placeholder="30" style="width: 50px; padding: 5px; margin-left: 5px;" min="0" step="1" />%
        </label>
      </div>
      
      <div class="form-group">
        <label class="checkbox-label">
          <input type="checkbox" name="netMargin" /> 净利率 >
          <input type="number" name="netMarginValue" placeholder="10" style="width: 50px; padding: 5px; margin-left: 5px;" min="0" step="1" />%
        </label>
      </div>
      
      <div class="form-group">
        <label class="checkbox-label">
          <input type="checkbox" name="growthRate" /> 净利润年化增长率 >
          <input type="number" name="growthRateValue" placeholder="15" style="width: 50px; padding: 5px; margin-left: 5px;" min="0" step="1" />%
        </label>
      </div>
      
      <div class="form-group">
        <label class="checkbox-label">
          <input type="checkbox" name="debtRatio" /> 资产负债率 <
          <input type="number" name="debtRatioValue" placeholder="60" style="width: 50px; padding: 5px; margin-left: 5px;" min="0" step="1" />%
        </label>
      </div>
      
      <div class="form-group">
        <label class="checkbox-label">
          <input type="checkbox" name="cashFlow" /> 现金流连续
          <input type="number" name="cashFlowValue" placeholder="12" style="width: 50px; padding: 5px; margin-left: 5px;" min="1" step="1" /> 月为正
        </label>
      </div>
      
      <div class="form-group">
        <label class="checkbox-label">
          <input type="checkbox" name="receivables" /> 应收账款比例 <
          <input type="number" name="receivablesValue" placeholder="30" style="width: 50px; padding: 5px; margin-left: 5px;" min="0" step="1" />%
        </label>
      </div>
    </form>
    
    <button class="btn btn-secondary" onclick="startScreening()">开始筛选</button>
    
    <h4 style="margin-top: 30px;">筛选结果：</h4>
    <div id="screeningResults">
      <div class="stock" data-stock="600036">
        <div class="stock-info">招商银行 (600036)</div>
        <div class="chart-container"><canvas id="chart4"></canvas></div>
        <div class="change positive">+2.01%</div>
      </div>
      <div class="stock" data-stock="601318">
        <div class="stock-info">中国平安 (601318)</div>
        <div class="chart-container"><canvas id="chart5"></canvas></div>
        <div class="change positive">+1.35%</div>
      </div>
    </div>
  </div>

  <script>
    // 全局状态管理
    const appState = {
      watchlist: [
        { code: '600519', name: '贵州茅台', change: 1.23 },
        { code: '300750', name: '宁德时代', change: -0.85 }
      ],
      strategies: [
        {
          id: 1,
          name: '策略一',
          type: 'TWAP + MACD',
          stocks: ['600519', '300750'],
          status: 'running'
        }
      ],
      selectedStocks: ['600519']
    };

    // DOM加载完成后初始化
    document.addEventListener('DOMContentLoaded', function() {
      initCharts();
      renderWatchlist();
      renderStrategies();
      
      // 点击模态框外部关闭模态框
      document.getElementById('strategyModal').addEventListener('click', function(e) {
        if (e.target === this) {
          toggleStrategyForm();
        }
      });
    });

    // 初始化图表
    function initCharts() {
      createChart("chart1", [100, 102, 101, 103, 105, 106], true);
      createChart("chart2", [300, 295, 298, 290, 285, 287], false);
      createChart("chart3", [100, 102, 104, 103, 105, 108], true);
      createChart("chart4", [30, 32, 31, 33, 34, 36], true);
      createChart("chart5", [45, 46, 45.5, 46.2, 46.5, 46.8], true);
    }

    // 渲染自选股票列表
    function renderWatchlist() {
      const watchlistEl = document.getElementById('watchlist');
      watchlistEl.innerHTML = '';
      
      appState.watchlist.forEach(stock => {
        const stockEl = document.createElement('div');
        stockEl.className = 'stock';
        stockEl.dataset.stock = stock.code;
        stockEl.innerHTML = `
          <div class="stock-info">${stock.name} (${stock.code})</div>
          <div class="chart-container"><canvas id="chart-${stock.code}"></canvas></div>
          <div class="change ${stock.change >= 0 ? 'positive' : 'negative'}">
            ${stock.change >= 0 ? '+' : ''}${stock.change.toFixed(2)}%
          </div>
        `;
        watchlistEl.appendChild(stockEl);
        
        // 为每只股票创建图表
        createChart(`chart-${stock.code}`, generateRandomChartData(), stock.change >= 0);
      });
    }

    // 渲染策略列表
    function renderStrategies() {
      const strategyListEl = document.getElementById('strategyList');
      strategyListEl.innerHTML = '';
      
      appState.strategies.forEach(strategy => {
        const strategyEl = document.createElement('div');
        strategyEl.className = 'strategy';
        strategyEl.style.marginTop = '20px';
        strategyEl.style.padding = '15px';
        strategyEl.style.background = 'var(--light-bg)';
        strategyEl.style.borderRadius = '4px';
        
        strategyEl.innerHTML = `
          <strong>${strategy.name}：</strong> ${strategy.type}<br />
          <small>股票：${strategy.stocks.map(code => getStockName(code)).join('、')}</small>
          <div style="margin-top: 10px;">
            <span class="badge" style="background: ${strategy.status === 'running' ? '#e3f2fd' : '#ffebee'}; 
              color: ${strategy.status === 'running' ? '#1976d2' : '#d32f2f'}; 
              padding: 2px 8px; border-radius: 12px; font-size: 12px;">
              ${strategy.status === 'running' ? '运行中' : '已停止'}
            </span>
            <span style="float: right;">
              <button class="btn btn-secondary btn-small" onclick="viewStrategyDetail(${strategy.id})">详情</button>
              <button class="btn btn-small" style="margin-left: 5px;" 
                onclick="${strategy.status === 'running' ? 'stopStrategy' : 'startStrategy'}(${strategy.id})">
                ${strategy.status === 'running' ? '停止' : '启动'}
              </button>
            </span>
          </div>
        `;
        
        strategyListEl.appendChild(strategyEl);
      });
    }

    // 获取股票名称
    function getStockName(code) {
      const stock = appState.watchlist.find(s => s.code === code);
      return stock ? stock.name : code;
    }

    // 生成随机图表数据
    function generateRandomChartData() {
      const data = [];
      let lastValue = 100 + Math.random() * 50;
      
      for (let i = 0; i < 6; i++) {
        lastValue = lastValue * (0.995 + Math.random() * 0.01);
        data.push(lastValue);
      }
      
      return data;
    }

    // 切换标签页
    function showTab(index) {
      document.querySelectorAll('.tab').forEach((tab, i) => {
        tab.classList.toggle('active', i === index);
        document.getElementById('tab' + i).classList.toggle('active', i === index);
      });
      
      // 如果切换到图表标签页，重新渲染图表以确保正确显示
      if (index === 0) {
        setTimeout(() => {
          document.querySelectorAll('.chart-container canvas').forEach(canvas => {
            const id = canvas.id;
            const stockCode = id.replace('chart-', '');
            const stock = appState.watchlist.find(s => s.code === stockCode);
            if (stock) {
              createChart(id, generateRandomChartData(), stock.change >= 0);
            }
          });
        }, 100);
      }
    }

    // 切换策略表单显示/隐藏
    function toggleStrategyForm() {
      const modal = document.getElementById('strategyModal');
      const isOpening = modal.style.display !== 'block';
      
      modal.style.display = isOpening ? 'block' : 'none';
      
      // 阻止背景滚动
      document.body.style.overflow = isOpening ? 'hidden' : '';
      
      if (isOpening) {
        document.getElementById('stockSearchInput').focus();
      }
    }

    // 防抖搜索
    let searchTimeout;
    function debounceSearch() {
      clearTimeout(searchTimeout);
      searchTimeout = setTimeout(searchStocks, 300);
    }

    // 搜索股票
    function searchStocks() {
      const input = document.getElementById('stockSearchInput').value.trim();
      const results = document.getElementById('searchResults');
      
      results.innerHTML = '<div class="loading">搜索中...</div>';
      results.style.display = 'block';
      
      if (input === '') {
        results.innerHTML = '<div class="loading">输入股票代码或名称搜索...</div>';
        return;
      }
      
      // 模拟API请求延迟
      setTimeout(() => {
        // 模拟搜索结果
        const mockResults = [
          { code: '000001', name: '平安银行' },
          { code: '000002', name: '万科A' },
          { code: '601318', name: '中国平安' },
          { code: '600519', name: '贵州茅台' },
          { code: '000858', name: '五粮液' }
        ];
        
        const filteredResults = mockResults.filter(stock => 
          stock.name.includes(input) || stock.code.includes(input)
        );
        
        if (filteredResults.length === 0) {
          results.innerHTML = '<div class="loading">没有找到匹配的股票</div>';
          return;
        }
        
        results.innerHTML = '';
        filteredResults.forEach(stock => {
          if (!appState.selectedStocks.includes(stock.code)) {
            const div = document.createElement('div');
            div.className = 'stock-search-result';
            div.innerHTML = `
              <span>${stock.name} (${stock.code})</span>
              <button class="btn btn-primary btn-small" onclick="addStock('${stock.code}', '${stock.name}')">添加</button>
            `;
            results.appendChild(div);
          }
        });
      }, 500);
    }

    // 添加股票
    function addStock(code, name) {
      if (!appState.selectedStocks.includes(code)) {
        appState.selectedStocks.push(code);
        renderSelectedStocks();
      }
      
      document.getElementById('stockSearchInput').value = '';
      document.getElementById('searchResults').style.display = 'none';
    }

    // 移除股票
    function removeStock(button) {
      const stockEl = button.closest('.stock');
      const code = stockEl.dataset.stock;
      
      appState.selectedStocks = appState.selectedStocks.filter(c => c !== code);
      renderSelectedStocks();
    }

    // 渲染已选股票
    function renderSelectedStocks() {
      const container = document.getElementById('selectedStocks');
      container.innerHTML = '';
      
      appState.selectedStocks.forEach(code => {
        const stock = appState.watchlist.find(s => s.code === code) || { code, name: code };
        
        const stockEl = document.createElement('div');
        stockEl.className = 'stock';
        stockEl.dataset.stock = code;
        stockEl.innerHTML = `
          <div class="stock-info">${stock.name} (${stock.code})</div>
          <div class="chart-container"><canvas id="selected-chart-${code}"></canvas></div>
          <button class="btn btn-small" onclick="removeStock(this)">移除</button>
        `;
        container.appendChild(stockEl);
        
        createChart(`selected-chart-${code}`, generateRandomChartData(), true);
      });
    }

    // 开始筛选
    function startScreening() {
      const form = document.getElementById('screeningForm');
      const criteria = {
        roe: form.roe.checked ? parseFloat(form.roeValue.value) : null,
        grossMargin: form.grossMargin.checked ? parseFloat(form.grossMarginValue.value) : null,
        // 其他筛选条件...
      };
      
      // 模拟筛选过程
      document.getElementById('screeningResults').innerHTML = `
        <div style="padding: 20px; text-align: center; color: #666;">
          <div class="loading">正在筛选符合条件的股票...</div>
        </div>
      `;
      
      setTimeout(() => {
        // 模拟筛选结果
        const mockResults = [
          { code: '600036', name: '招商银行', change: 2.01 },
          { code: '601318', name: '中国平安', change: 1.35 },
          { code: '000333', name: '美的集团', change: 0.78 }
        ];
        
        const resultsContainer = document.getElementById('screeningResults');
        resultsContainer.innerHTML = '';
        
        mockResults.forEach(stock => {
          const stockEl = document.createElement('div');
          stockEl.className = 'stock';
          stockEl.dataset.stock = stock.code;
          stockEl.innerHTML = `
            <div class="stock-info">${stock.name} (${stock.code})</div>
            <div class="chart-container"><canvas id="screened-chart-${stock.code}"></canvas></div>
            <div class="change ${stock.change >= 0 ? 'positive' : 'negative'}">
              ${stock.change >= 0 ? '+' : ''}${stock.change.toFixed(2)}%
            </div>
          `;
          resultsContainer.appendChild(stockEl);
          
          createChart(`screened-chart-${stock.code}`, generateRandomChartData(), stock.change >= 0);
        });
      }, 1500);
    }

    // 查看策略详情
    function viewStrategyDetail(id) {
      const strategy = appState.strategies.find(s => s.id === id);
      if (strategy) {
        alert(`策略详情:\n名称: ${strategy.name}\n类型: ${strategy.type}\n股票: ${strategy.stocks.join(', ')}`);
      }
    }

    // 停止策略
    function stopStrategy(id) {
      const strategy = appState.strategies.find(s => s.id === id);
      if (strategy) {
        strategy.status = 'stopped';
        renderStrategies();
      }
    }

    // 启动策略
    function startStrategy(id) {
      const strategy = appState.strategies.find(s => s.id === id);
      if (strategy) {
        strategy.status = 'running';
        renderStrategies();
      }
    }

    // 创建图表
    function createChart(id, data, isPositive = true) {
      const canvas = document.getElementById(id);
      if (!canvas) return;
      
      // 清除旧图表实例
      if (canvas.chart) {
        canvas.chart.destroy();
      }
      
      canvas.width = 200;
      canvas.height = 60;
      const ctx = canvas.getContext('2d');

      const color = isPositive ? '#4CAF50' : '#F44336';
      
      const gradient = ctx.createLinearGradient(0, 0, 0, 60);
      gradient.addColorStop(0, `${color}40`);
      gradient.addColorStop(1, `${color}00`);

      canvas.chart = new Chart(ctx, {
        type: 'line',
        data: {
          labels: data.map((_, i) => ''),
          datasets: [{
            data: data,
            borderColor: color,
            backgroundColor: gradient,
            borderWidth: 2,
            tension: 0.4,
            fill: true,
            pointRadius: 0
          }]
        },
        options: {
          responsive: false,
          maintainAspectRatio: false,
          plugins: { 
            legend: { display: false },
          },
          scales: {
            x: { 
              display: false,
              grid: { display: false }
            },
            y: { 
              display: false,
              grid: { display: false },
              beginAtZero: false
            }
          },
          layout: {
            padding: {
              left: 0,
              right: 0,
              top: 0,
              bottom: 0
            }
          }
        }
      });
    }
  </script>
  
  <script>
    // 添加触摸事件支持
    document.addEventListener('touchmove', function(e) {
      // 如果模态框打开且内容可滚动，允许滚动
      const modal = document.getElementById('strategyModal');
      if (modal.style.display === 'block') {
        const modalContent = document.querySelector('.modal-content');
        if (modalContent.scrollHeight > modalContent.clientHeight) {
          e.stopPropagation();
        }
      }
    }, { passive: false });
  </script>
</body>
</html>